package com.moxi.mogublog.web.restapi.xuan;


import com.moxi.cloudblog.base.exception.ThrowableUtils;
import com.moxi.cloudblog.base.validator.group.Insert;
import com.moxi.cloudblog.base.validator.group.Update;
import com.moxi.mogublog.commons.feign.AdminFeignClient;
import com.moxi.mogublog.commons.vo.BlogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "博客相关接口", tags = {"博客相关接口"})
@RestController
@RequestMapping("/blog")
@Slf4j
public class WebBlogRestApi {

    @Resource
    private AdminFeignClient adminFeignClient;

    @ApiOperation(value = "web编辑博客", notes = "web编辑博客", response = String.class)
    @PostMapping("/editBlog")
    public String edit(@Validated({Update.class}) @RequestBody BlogVO blogVO, BindingResult result) {
        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        return adminFeignClient.editBlog(blogVO);
    }

    @ApiOperation(value = "web增加博客", notes = "web增加博客", response = String.class)
    @PostMapping("/addBlog")
    public String add(@Validated({Insert.class}) @RequestBody BlogVO blogVO, BindingResult result) {
        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        return adminFeignClient.addBlog(blogVO);
    }

    @GetMapping("/test")
    public String test(){
        return adminFeignClient.test();
    }
}
